/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-06-25 14:26:29
 * @LastEditors: paddies
 * @LastEditTime: 2024-06-25 17:18:12
 * @FilePath: /shared_components/lib/luntai-components/build-after-sale-info/buildAfterSaleInfo.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-image/buildImage.dart';
import 'package:shared_components/build-line/buildLine.dart';

Widget buildAfterSaleInfo({dynamic afterSale}) {
  var afterSaleRequest = [].obs;
  var afterSaleResponse = [].obs;
  if (afterSale != null) {
    if (afterSale["afterSaleRequest"] != null) {
      afterSaleRequest.value = afterSale["afterSaleRequest"];
    }
    if (afterSale["afterSaleRequest"] != null) {
      afterSaleResponse.value = afterSale["afterSaleResponse"];
    }
  }
  return Column(
    children: [
      Visibility(
          visible: afterSaleRequest.value.isNotEmpty,
          child: Container(
            width: double.infinity,
            padding:
                EdgeInsetsDirectional.symmetric(vertical: 15, horizontal: 15),
            // height: 50,
            color: Colors.white,
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              const Text(
                '售后申请信息',
                style: TextStyle(
                    color: Color(0xff1D1D1F), fontWeight: FontWeight.bold),
              ),
              ...afterSaleRequest.value.map((e) {
                return Padding(
                    padding: const EdgeInsets.symmetric(vertical: 10),
                    child: Row(
                      children: [
                        Text(
                          showText(e["name"]),
                          style:
                              TextStyle(color: Color(0xff1D1D1F), fontSize: 12),
                        ),
                        Expanded(
                            flex: 1,
                            child: SizedBox(
                                width: double.infinity,
                                child: Align(
                                    alignment: Alignment.centerRight,
                                    child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.end,
                                        children: [
                                          Visibility(
                                              visible:
                                                  showText(e["type"]) == "text",
                                              child: Text(
                                                showText(e["value"]),
                                                overflow: TextOverflow.ellipsis,
                                                maxLines: 1,
                                                style: TextStyle(
                                                  color: Color(0xff7E7D83),
                                                  fontSize: 12,
                                                ),
                                              )),
                                          Visibility(
                                              visible:
                                                  showText(e["type"]) == "url",
                                              child: Column(
                                                children: [
                                                  ...getUrlList(e["value"])
                                                      .map((u) {
                                                    return Container(
                                                      width: 50,
                                                      height: 50,
                                                      child: buildImage(
                                                          provider: true,
                                                          type: "ClipRect",
                                                          url: showText(u)),
                                                    );
                                                  }).toList(),
                                                ],
                                              ))
                                        ]))))
                      ],
                    ));
              }).toList()
            ]),
          )),
      Visibility(
        visible: afterSaleResponse.value.isNotEmpty,
        child: buildLine(),
      ),
      Visibility(
          visible: afterSaleResponse.value.isNotEmpty,
          child: Container(
              width: double.infinity,
              padding:
                  EdgeInsetsDirectional.symmetric(vertical: 15, horizontal: 15),
              // height: 50,
              color: Colors.white,
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text(
                      '售后处理信息',
                      style: TextStyle(
                          color: Color(0xff1D1D1F),
                          fontWeight: FontWeight.bold),
                    ),
                    ...afterSaleResponse.value.map((e) {
                      return Padding(
                          padding: const EdgeInsets.symmetric(vertical: 10),
                          child: Row(
                            children: [
                              Text(
                                showText(e["name"]),
                                style: TextStyle(
                                    color: Color(0xff1D1D1F), fontSize: 12),
                              ),
                              Expanded(
                                  flex: 1,
                                  child: SizedBox(
                                      width: double.infinity,
                                      child: Align(
                                          alignment: Alignment.centerRight,
                                          child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.end,
                                              children: [
                                                Visibility(
                                                    visible:
                                                        showText(e["type"]) ==
                                                            "text",
                                                    child: Text(
                                                      showText(e["value"]),
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      maxLines: 1,
                                                      style: TextStyle(
                                                        color:
                                                            Color(0xff7E7D83),
                                                        fontSize: 12,
                                                      ),
                                                    )),
                                                Visibility(
                                                    visible:
                                                        showText(e["type"]) ==
                                                            "url",
                                                    child: Column(
                                                      children: [
                                                        ...getUrlList(
                                                                e["value"])
                                                            .map((u) {
                                                          return Container(
                                                            width: 50,
                                                            height: 50,
                                                            child: buildImage(
                                                                provider: true,
                                                                type:
                                                                    "ClipRect",
                                                                url: showText(
                                                                    u)),
                                                          );
                                                        }).toList(),
                                                      ],
                                                    ))
                                              ]))))
                            ],
                          ));
                    }).toList()
                  ]))),
      Visibility(
        visible: afterSaleResponse.value.isNotEmpty,
        child: buildLine(),
      ),
    ],
  );
}

List getUrlList(String urls) {
  return urls.split(",");
}
